import { _themeData } from "../../../service/api";

Page({
  data: {
    themeList: [],
    page: 1, // 当前页
    size: 10, // 每页显示条数
    totalPage: 0, // 总页数
    scrollTop: 0, // 回到顶部
  },
  onLoad: function (options) {
    this.initData();
  },
  initData() {
    let { page, size } = this.data;
    _themeData({ page, size }).then((res) => {
      const num = Math.ceil(res.count[0]["count(*)"] / size);
      this.setData({
        scrollTop: 0,
        themeList: res.result,
        totalPage: num,
      });
    });
  },
  // 上一页
  handlePrevPage() {
    this.setData({ page: parseInt(this.data.page) - 1 });
    this.initData();
  },
  // 下一页
  handleNextPage() {
    this.setData({ page: parseInt(this.data.page) + 1 });
    this.initData();
  },
});
